<html>
<body>
<form action="calculator.php" method="GET">
Input: <input type="text" name="name" />
<input type="submit" />
</form>
<?php
if($_GET["name"])
{
echo "Result <br/>";
if
( 
(preg_match("[A-Z]", $_GET["name"],$matches))
|| (preg_match("[a-z]", $_GET["name"],$matches))
|| (preg_match("[/0]", $_GET["name"],$matches))
|| ((preg_match("/\D\D+/", $_GET["name"],$matches))
&&(!($matches[0]=="/-"))&&(!($matches[0]=="+-"))&&(!($matches[0]=="*-"))  )
)
  echo "Invalid expression ".$_GET["name"];
else 
{
echo $_GET["name"]." = ";
$equ= $_GET["name"];
eval("\$ans= $equ;");
if (is_numeric ($ans))
echo $ans;
else 
echo "Invalid expression".$_GET["name"];
}
}
?>
</body>
</html>